//
//  StockManagementViewController.m
//  TryShopping
//
//  Created by LiYinDi on 16/6/21.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "StockManagementViewController.h"
#import "SpecDetailTableViewCell.h"
#import "StockManageHeadModel.h"
#import "SpecDetailCellModel.h"
#import "StockManagePopView.h"
#import "TheLoginViewController.h"
#import "StockManagementPopListModel.h"
#import "FilterView.h"
#import "CashierNewViewController.h"
@interface StockManagementViewController ()<SpecDetailCellDelegate,FilterViewDelegate>
{
    NSMutableArray *headerModelArray;
    
    
    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
    
    NSString *orderFieldStr;
    NSString *orderSortStr;
    NSMutableArray *searchBeans;
    NSInteger clickIndex;
}
@end

@implementation StockManagementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    UIView *myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*btnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone .titleLabel .font=[UIFont systemFontOfSize:17];
    [btnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone];
    myToolBar.alpha=alp;
    _searchTextField.inputAccessoryView = myToolBar;
    
    headerModelArray=[NSMutableArray array];
    searchBeans=[NSMutableArray array];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=YES;
    [self setAutoLayout];
    [_numberBtn addTarget:self action:@selector(numberBtnClick) forControlEvents:UIControlEventTouchUpInside];
    searchBeans=[NSMutableArray array];
    orderFieldStr=@"";
    orderSortStr=@"";
    if(!_searchKeyWordStr)
    {
        _searchKeyWordStr=@"";
    }
    
    _PageIndex=0;
    [self loadItemNextPage:_PageIndex];
    UIImage *img=[UIImage imageNamed:@"saoyisao_new"];
    UIImage *tinted = [img rt_tintedImageWithColor:zhonghuiColor];
    [_scanBtn setImage:tinted forState:UIControlStateNormal];

    //saoyisao_new
    // Do any additional setup after loading the view from its nib.
}
-(void)OnTapDone
{
    [_searchTextField resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [headerModelArray removeAllObjects];
    
    _searchKeyWordStr=_searchTextField.text;
    _PageIndex=0;
    [self loadItemNextPage:_PageIndex];
    return YES;
}

- (IBAction)newestBtnClick:(id)sender {
    orderFieldStr=@"date";
    orderSortStr=@"";
    [_newestBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [headerModelArray removeAllObjects];
    _PageIndex=0;
    [self loadItemNextPage:_PageIndex];
}
- (void)numberBtnClick{
    [_newestBtn setTitleColor:[UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
   orderFieldStr=@"quantity";
    if (clickIndex%2==0) {
        orderSortStr=@"asc";
        [_numberImageView setImage:[UIImage imageNamed:@"shang_hight"]];
    }
    else
    {
         orderSortStr=@"desc";
        [_numberImageView setImage:[UIImage imageNamed:@"xia_hight"]];
    }
    clickIndex++;
    [headerModelArray removeAllObjects];
    _PageIndex=0;
    [self loadItemNextPage:_PageIndex];
}
- (IBAction)filterBtnClick:(id)sender {
    FilterView *filterView=[FilterView FilterViewWithSize:CGSizeMake(ScreenWidth, ScreenHeight)];
    filterView.typeStr=@"inventory";
    filterView.delegate=self;
    filterView.selectedSearchBeansArray=searchBeans;
    [filterView show];
}
#pragma mark FilterViewDelegate
-(void)confirmFilter:(NSMutableArray *)searchBeansArray
{
    if (searchBeansArray.count==0) {
        orderFieldStr=@"date";
        orderSortStr=@"";
        [_newestBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    searchBeans=searchBeansArray;
    [headerModelArray removeAllObjects];
    _PageIndex=0;
    [self loadItemNextPage:_PageIndex];
    
    
   
}

-(void) loadItemNextPage:(NSUInteger)oldPageNum {
    
    if(oldPageNum!=0 && _TotalCount<=headerModelArray.count)
        return;
    if(oldPageNum == 0){
        [headerModelArray removeAllObjects];
        [_tableView reloadData];
    }
    _PageIndex=oldPageNum+1;
    [self requestItemList: _PageIndex pageSize:20];
}
-(void)requestItemList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    [Global showIndeterminateHud:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:Token forKey:@"tokenId"];
    NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
    NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
    [params setObject:pageSizeNumber forKey:@"pageSize"];
    [params setObject:pageIndexNumber forKey:@"pageIndex"];
    
    [params setObject:orderFieldStr forKey:@"orderField"];
    [params setObject:orderSortStr forKey:@"orderSort"];
    [params setObject:_searchKeyWordStr forKey:@"sword"];
    [params setObject:searchBeans forKey:@"searchBeans"];
    
   NSLog(@"params^^^^===%@",params);
    [HttpRequest requestData:@"Product/Inventory/List" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                _TotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
//              NSLog(@"******===%@",severDataDict.dataDict);
                if (searchBeans.count>0) {

                [_filterBtn setTitleColor:[UIColor colorWithRed:90.0f/255.0f green:130.0f/255.0f blue:26.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
                UIImage *img=[UIImage imageNamed:@"shaixuan_hight"];
                UIImage *tinted = [img rt_tintedImageWithColor:luseColor];
                [_filterBtn setImage:tinted forState:UIControlStateNormal];
                }else{
                
                    [_filterBtn setTitleColor:[UIColor colorWithRed:102/255.0f green:102/255.0f blue:102/255.0f alpha:1.0] forState:UIControlStateNormal];
                    UIImage *img=[UIImage imageNamed:@"shaixuan_hight"];
                    UIImage *tinted = [img rt_tintedImageWithColor:shenhuiColor];
                    [_filterBtn setImage:tinted forState:UIControlStateNormal];
                }
                if (_TotalCount%20!=0) {
                    _TotalPage=_TotalCount/20+1;
                }
                else if (_TotalCount%20==0)
                {
                    _TotalPage=_TotalCount/20;
                }
                NSMutableArray * mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                for (NSDictionary *dic in mItemsArray) {
                    StockManageHeadModel *dataModel=[StockManageHeadModel dataModelWithDict:dic];
                    [headerModelArray addObject:dataModel];
                    
                }
                [_tableView reloadData];
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                //  [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    TheLoginViewController *loginVC=[[TheLoginViewController alloc] init];//2.0{9个参数 少2个}
                    [self.navigationController pushViewController:loginVC animated:YES];
                }
                
            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
    
}
-(void)requestProductDetail:(NSString *)itemIdStr parentIndex:(NSInteger)parentIndex
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
//    if (Token ==nil) {
//        Token=@"dd";
//    }
    [Global showIndeterminateHud:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:Token forKey:@"tokenId"];
    [params setObject:itemIdStr forKey:@"itemId"];
    
    [HttpRequest requestData:@"Product/Inventory/ItemSpec" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {              //NSLog(@"seve22//2====%@",severDataDict.dataDict);
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                 NSMutableArray *detailCellModelArray=[NSMutableArray array];
                NSMutableArray * specListArray= [severDataDict.dataDict objectForKey:@"DataLine"] ;
//                NSLog(@"specListArray^^^^===%@",specListArray);
                for (NSDictionary *dic in specListArray) {
                    SpecDetailCellModel *dataModel=[SpecDetailCellModel dataModelWithDict:dic];
                    [detailCellModelArray addObject:dataModel];
                    
                }
                StockManageHeadModel *headerModel=headerModelArray[parentIndex];
                headerModel.modelArray=detailCellModelArray;
                

               [_tableView reloadSections:[NSIndexSet indexSetWithIndex:parentIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
                }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
    
    
}

- (IBAction)topScanBtnClick:(id)sender {
    CashierNewViewController *cashierNewVC=[[CashierNewViewController alloc] init];
    [Global setScanTitle:@"扫存货"];
    [Global setType:@"SCANSTOCKMANAGE"];
//    cashierNewVC.scanResultStr=@"backType";
    [self.navigationController pushViewController:cashierNewVC animated:YES];
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//    NSLog(@"headerheaderrrr");
    StockManageHeadModel *headerModel=headerModelArray[section];
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,122)];
    [view setBackgroundColor:[UIColor whiteColor]];
    
    UIImageView *productImageView=[[UIImageView alloc] initWithFrame:CGRectMake(15, 20, 82, 82)];
    productImageView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    productImageView.layer.borderWidth= 0.5f;
//    [productImageView setImageWithURL:[NSURL URLWithString:headerModel.imageUrlFull]];
    [productImageView setImageWithURL:[NSURL URLWithString:headerModel.imageUrlFull] placeholderImage:[UIImage imageNamed:@"zhengfangxing"]];

    [view addSubview:productImageView];
    
    
    UILabel *productNameLabel=[[UILabel alloc] initWithFrame:CGRectMake(productImageView.right+12, 20, ScreenWidth-116, 1)];
    [productNameLabel setText:headerModel.itemName];
     productNameLabel.font=[UIFont systemFontOfSize:14];
    productNameLabel.numberOfLines=2;
    [productNameLabel sizeToFit];
    
   
    productNameLabel.textColor=[UIColor colorWithRed:51.0/255.0f green:51.0/255.0f  blue:51.0/255.0f  alpha:1.0];
    [view addSubview:productNameLabel];
    
    UILabel *productPriceLabel=[[UILabel alloc] initWithFrame:CGRectMake(productImageView.right+12, productNameLabel.bottom+5, productNameLabel.left , 15)];
    [productPriceLabel setText:[NSString stringWithFormat:@"¥%0.02f",[headerModel.salePrice floatValue]]];
    productPriceLabel.font=[UIFont systemFontOfSize:12];
    productPriceLabel.textColor=[UIColor colorWithRed:102.0/255.0f green:102.0/255.0f  blue:102.0/255.0f  alpha:1.0];
    [view addSubview:productPriceLabel];
    
    UILabel *productInvLabel=[[UILabel alloc] initWithFrame:CGRectMake(productImageView.right+12, 85, 185, 15)];
    productInvLabel.font=[UIFont systemFontOfSize:12];
    productInvLabel.textColor=luseColor;
    NSString *str=[NSString stringWithFormat:@"本店库存 %d",[headerModel.invQty intValue]];
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:str];
    [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0] range:NSMakeRange(0, 4)];
    productInvLabel.attributedText=attriString;
//    productInvLabel.textAlignment=NSTextAlignmentRight;
    [view addSubview:productInvLabel];
    
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10,121,ScreenWidth-20,0.5)];
    if (!headerModel.isOpened) {
        lineLabel.backgroundColor=[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f  blue:238.0/255.0f  alpha:1];
    }
    else
    {
        lineLabel.backgroundColor=[UIColor colorWithRed:250.0/255.0f green:250.0/255.0f  blue:250.0/255.0f  alpha:1];
    }
    [view addSubview:lineLabel];
//
    
    
    if ([headerModel.specType intValue]!=0) {
        
        UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        detailBtn.frame=CGRectMake(ScreenWidth-110, 72, 100, 30);
        detailBtn.layer.borderWidth=0.5;
        detailBtn.layer.borderColor=[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:240.0/255.0f].CGColor;
        detailBtn.tag=section;
        detailBtn.titleLabel.font = [UIFont systemFontOfSize: 13.0];
        if ( !headerModel.isOpened) {
            [detailBtn setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
        }
        else
        {
            [detailBtn setImage:[UIImage imageNamed:@"shouqi_shang"] forState:UIControlStateNormal];
        }
        
        [detailBtn setTitle:@"规格明细" forState: UIControlStateNormal];
        
        [detailBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 30)];
        [detailBtn setImageEdgeInsets:UIEdgeInsetsMake(0,68, 0, 0)];
        
        
        [detailBtn setTitleColor:[UIColor colorWithRed:90.0/255.0f green:130.0/255.0f blue:26.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
        [detailBtn addTarget:self action:@selector(detaiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:detailBtn];

        
    }
    else {
        UIButton *moreBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        moreBtn.frame=CGRectMake(ScreenWidth-110, 72, 100, 30);
        UIImage *image=[UIImage imageNamed:@"shouqi"];
        [moreBtn setImage:image forState:UIControlStateNormal];
        [moreBtn setTitle:@"更多库存" forState:UIControlStateNormal];
        [moreBtn setTitleColor:[UIColor colorWithRed:90.0/255.0f green:130.0/255.0f blue:26.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
        moreBtn.tag=section;
        moreBtn.titleLabel.font = [UIFont systemFontOfSize: 13.0];
        [moreBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 30)];
        [moreBtn setImageEdgeInsets:UIEdgeInsetsMake(0,68, 0, 0)];
        [moreBtn addTarget:self action:@selector(headerMoreBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:moreBtn];
    }
    
    if (section== [headerModelArray count] - 1) {
        NSLog(@"###LOADING???");
        if (_PageIndex<=_TotalPage) {
            
            [self loadItemNextPage:_PageIndex];
        }
        
    }

    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 122;
}

-(void)detaiBtnClick:(UIButton *)sender
{
    StockManageHeadModel *headerModel=headerModelArray[sender.tag];
    [headerModel.modelArray removeAllObjects];
    if (!headerModel.isOpened) {
//    if (sectionIndex!=sender.tag) {
          headerModel.isOpened = YES;
    [self requestProductDetail:headerModel.itemId parentIndex:sender.tag];
    }
    
    else
    {
          headerModel.isOpened = NO;
    [_tableView reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
  
    [headerModelArray replaceObjectAtIndex:sender.tag withObject:headerModel];
//    sectionIndex=sender.tag;
//
}
-(void)headerMoreBtnClick:(UIButton *)sender
{
    StockManageHeadModel *headerModel=headerModelArray[sender.tag];
    StockManagePopView *popVC=[[StockManagePopView alloc] init];
    [popVC show:headerModel.itemId];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return headerModelArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 59;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    StockManageHeadModel *groupModel = headerModelArray[section];
    NSInteger count = groupModel.isOpened? groupModel.modelArray.count:0;
    return count;
    
    //    return 5;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * const  ResultTableViewCellIdentifier = @"SpecDetailTableViewCell";
    SpecDetailTableViewCell *cell=( SpecDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
    if (cell==nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SpecDetailTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    cell.delegate=self;
    cell.parentIndex=indexPath.section;
    cell.moreBtn.tag=indexPath.row;
    
    StockManageHeadModel *headerModel=headerModelArray[indexPath.section];
    
    SpecDetailCellModel *model=headerModel.modelArray[indexPath.row];
    
    cell.model=model;
  
    if (headerModel.modelArray.count !=indexPath.row+1) {
        UIImageView *_hengxian = [[UIImageView alloc]initWithFrame:CGRectMake(10,59-0.45, ScreenWidth-20, 0.45)];
        _hengxian.image=[UIImage imageNamed:@"hengxian"];
        [cell.contentView addSubview:_hengxian];
        
    }
    
    if (headerModel.modelArray.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 59-0.40, ScreenWidth, 0.30)];
        lineLabel1.backgroundColor=qianhuiColor;
        [cell.contentView addSubview:lineLabel1];
        
    }

    
   
    
   
    return cell;
}
#pragma mark cellDelegate
-(void)moreButton:(NSUInteger)tag parentIndex:(NSUInteger)parentIndex
{
    StockManageHeadModel *headerModel=headerModelArray[parentIndex];
    
    SpecDetailCellModel *model=headerModel.modelArray[tag];
    StockManagePopView *popVC=[[StockManagePopView alloc] init];
    [popVC show:model.specId];
}
-(void)setAutoLayout
{
    [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        make.height.equalTo(@102);
    }];

    [_topLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topView.mas_left) ;
        make.right.equalTo(_topView.mas_right) ;
        make.height.equalTo(@0.5) ;
        make.bottom.equalTo(_topView.mas_top).with.offset(64);
    }];
    [_searchParentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_backBtn.mas_right);
        make.height.equalTo(@35);
        make.right.equalTo(self.view.mas_right).with.offset(-40);
        make.bottom.equalTo(_topLineLabel.mas_top).with.offset(-5);
    }];
    [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_searchParentView.mas_centerY);
        make.height.equalTo(@30);
        make.width.equalTo(@45);
        make.left.equalTo(self.view.mas_left);
    }];
    [_scanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_searchParentView.mas_centerY);
        make.height.equalTo(@30);
        make.width.equalTo(@30);
        make.left.equalTo(_searchParentView.mas_right);
    }];
    
    [_top_BottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_topView.mas_left);
        make.right.equalTo(_topView.mas_right);
        make.top.equalTo(_topLineLabel.mas_bottom);
        make.height.equalTo(@40);
    }];
    [_newestBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_top_BottomView.mas_left);
        make.width.equalTo(@100);
        make.top.equalTo(_top_BottomView.mas_top);
        make.height.equalTo(@40);
    }];
    [_numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_top_BottomView.mas_centerX);
        make.width.equalTo(@100);
        make.top.equalTo(_top_BottomView.mas_top);
        make.height.equalTo(@40);
    }];
    [_filterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_top_BottomView.mas_right);
        make.width.equalTo(@100);
        make.top.equalTo(_top_BottomView.mas_top);
        make.height.equalTo(@40);
    }];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(_topView.mas_bottom);
        make.bottom.equalTo(self.view.mas_bottom);
        
    }];
    
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
